<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Transportation Information</title></head>

<body>

<H2>Transportation Information</H2>
<hr>
<?php
	echo "Hello";
	/*function getJson_traveltime($mode,$origin_lat,$origin_lon,$des_lat,$des_lon){
		$BASE_URL_TRAVELTIME = "http://api2.walkscore.com/api/v1/traveltime/json?"; 
		$API_KEY = "e6b9ab999aecb4b879793f684a751825";
		
		$query_url_traveltime = $BASE_URL_TRAVELTIME . "wsapikey=" . $API_KEY."&mode=".$mode."&origin=".$origin_lat.",".$origin_lon."&destination=".$des_lat.",".$des_lon;
		
		$session_traveltime = curl_init($query_url_traveltime);  
		curl_setopt($session_traveltime, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($session_traveltime, CURLOPT_TIMEOUT, 1000); 
		curl_setopt( $session_traveltime, CURLOPT_ENCODING, "UTF-8" );
		$json_traveltime = curl_exec($session_traveltime);
		curl_close($session_traveltime);
		$response_traveltime = json_decode($json_traveltime);
		//echo $json_traveltime;
		return $response_traveltime;
		}
		
	function Geo($address){
		//echo "look up address".$address."<br>";
 
		$address = str_replace (" ", "+", urlencode($address));
		$details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$address."&sensor=false";
		
		//echo "look up address".$address.$details_url."<br>";
 
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $details_url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$response = json_decode(curl_exec($ch), true);
 
		// If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
		if ($response['status'] != 'OK') {
			return null;
			}
 
			//print_r($response);
			$geometry = $response['results'][0]['geometry'];
 
			$latitude = $geometry['location']['lat'];
			$longitude = $geometry['location']['lng'];
			//echo "look up geo".$latitude.",".$longitude."<br>";
			return $latitude.",".$longitude;
 
			/*$array = array(
			'longitude' => $geometry['location']['lng'],
			'latitude' => $geometry['location']['lat'],
			'location_type' => $geometry['location_type'],
			);
		}
		
	function getJson_transitscore($origin_lat,$origin_lon,$city,$state){
		$BASE_URL_TRANSITSCORE = "http://transit.walkscore.com/transit/score/?";
		$API_KEY = "e6b9ab999aecb4b879793f684a751825";
		$query_url_transitscore = $BASE_URL_TRANSITSCORE ."lat=".$origin_lat."&lon=".$origin_lon."&city=".$city."&state=".$state."&wsapikey=".$API_KEY;
		
		//echo $query_url_transitscore."<br>";
		
		$session_transitscore = curl_init($query_url_transitscore);  
		curl_setopt($session_transitscore, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($session_transitscore, CURLOPT_TIMEOUT, 1000); 
		curl_setopt( $session_transitscore, CURLOPT_ENCODING, "UTF-8" );
		$json_transitscore = curl_exec($session_transitscore);
		curl_close($session_transitscore);
		$response_transitscore = json_decode($json_transitscore);
		//echo $json_transitscore;
		return $response_transitscore;
		}
		
	function is_set( & $variable ) {
    if ( isset( $variable ) and ! is_null( $variable ) )
        return true;
    else
        return false;
	}
	
		$travel_mode = $_POST["transit"];	//user can choose four modes: walk, bike, drive and transit
		$origin_add = $_POST["fav_address"];
		$address_tkn = explode(",",$fav_add);
		//echo $address_tkn[1].urlencode($address_tkn[2]);
		$fav_add = $_POST["fav_address"];
		$origin_geo = Geo($origin_add);
		//echo "origin_geo".$origin_geo."<br>";
		$origin_geo_tkn = explode(",",$origin_geo);
		$fav_geo = Geo($fav_add);
		//echo "fav_geo".$fav_geo."<br>";
		$fav_geo_tkn = explode(",",$fav_geo);
		//$json_traveltime = getJson_traveltime($travel_mode,$origin_geo_tkn[0],$origin_geo_tkn[1],$fav_geo_tkn[0],$fav_geo_tkn[1]);
		$json_transitscore = getJson_transitscore($origin_geo_tkn[0],$origin_geo_tkn[1],urlencode($address_tkn[1]),urlencode($address_tkn[2]));
		//echo "Json :" .$json;
		
		//fetch traveltime
		if(is_set($json_traveltime->response->results)){
			$entries = array();
			$entries = $json_traveltime->response->results;

			foreach($entries as $entry){
				if(is_set($entry->travel_times)){
					$entries1 = array();
					$entries1 = $entry->travel_times;
		
					foreach($entries1 as $entry1){
						echo "Travel time(".$travel_mode."): ".number_format((float)(($entry1->seconds)/60 ), 2, '.', '')."  mins". "<br>";
						}
					}
				}
			}
			
		//fetch transit score information
		//echo "*****************************<br>";
		if(is_set( $json_transitscore->transit_score)){
			echo "Transit score: ".$json_transitscore->transit_score."<br>";}
		if(is_set( $json_transitscore->description)){
			echo "Description: ".$json_transitscore->description."<br>";}
		if(is_set( $json_transitscore->summary)){
					echo "Near by routes: ".$json_transitscore->summary."<br>";}
		
		
					
		//if(is_set( $json_transitscore->)){*/
			



?>
<hr>
</body></html>